load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("//bazel:canisters.bzl", "rust_canister")
load("//bazel:defs.bzl", "rust_ic_test_suite")

package(default_visibility = ["//visibility:public"])

rust_library(
    name = "icrc3_test_ledger",
    srcs = glob(["src/**/lib.rs"]),
    crate_name = "ic_icrc3_test_ledger",
    version = "0.1.0",
    deps = [
        # Keep sorted.
        "//packages/icrc-ledger-types:icrc_ledger_types",
        "@crate_index//:candid",
        "@crate_index//:ic-cdk",
        "@crate_index//:serde",
    ],
)

rust_canister(
    name = "icrc3_test_ledger_canister",
    srcs = ["src/main.rs"],
    crate_name = "ic_icrc3_test_ledger_canister",
    opt = "z",
    service_file = ":icrc3_test_ledger.did",
    version = "0.9.0",
    deps = [
        # Keep sorted.
        ":icrc3_test_ledger",
        "//packages/icrc-ledger-types:icrc_ledger_types",
        "//rs/ledger_suite/common/ledger_canister_core",
        "//rs/ledger_suite/icrc1",
        "@crate_index//:candid",
        "@crate_index//:ciborium",
        "@crate_index//:ic-cdk",
        "@crate_index//:ic-certification",
        "@crate_index//:leb128",
        "@crate_index//:num-traits",
        "@crate_index//:serde",
        "@crate_index//:serde_bytes",
    ],
)

rust_test(
    name = "icrc3_test_ledger_canister_test",
    crate = ":_wasm_icrc3_test_ledger_canister",
    data = [
        ":icrc3_test_ledger.did",
    ],
    env = {
        "CARGO_MANIFEST_DIR": "rs/ledger_suite/icrc1/test_utils/icrc3_test_ledger",
    },
    deps = [
        "@crate_index//:candid_parser",
    ],
)

rust_ic_test_suite(
    name = "icrc3_test_ledger_integration_test",
    srcs = ["tests/tests.rs"],
    data = [
        ":icrc3_test_ledger_canister.wasm.gz",
        "//rs/ledger_suite/icrc1/index-ng:index_ng_canister",
        "//rs/ledger_suite/icrc1/ledger:ledger_canister.wasm.gz",
    ],
    env = {
        "CARGO_MANIFEST_DIR": "rs/ledger_suite/icrc1/test_utils/icrc3_test_ledger",
        "IC_ICRC1_LEDGER_WASM_PATH": "$(rootpath //rs/ledger_suite/icrc1/ledger:ledger_canister.wasm.gz)",
        "ICRC3_TEST_LEDGER_CANISTER_WASM_PATH": "$(rootpath :icrc3_test_ledger_canister.wasm.gz)",
        "IC_ICRC1_INDEX_NG_WASM_PATH": "$(rootpath //rs/ledger_suite/icrc1/index-ng:index_ng_canister)",
    },
    deps = [
        # Keep sorted.
        ":icrc3_test_ledger",
        "//packages/icrc-ledger-types:icrc_ledger_types",
        "//rs/ledger_suite/icrc1",
        "//rs/ledger_suite/icrc1/index-ng",
        "//rs/ledger_suite/icrc1/ledger",
        "//rs/ledger_suite/icrc1/test_utils",
        "//rs/ledger_suite/test_utils/state_machine_helpers:ic-ledger-suite-state-machine-helpers",
        "//rs/ledger_suite/tests/sm-tests:ic-ledger-suite-state-machine-tests",
        "//rs/state_machine_tests",
        "//rs/test_utilities/load_wasm",
        "//rs/types/base_types",
        "@crate_index//:candid",
        "@crate_index//:ciborium",
        "@crate_index//:ic-cbor",
        "@crate_index//:ic-certification",
        "@crate_index//:leb128",
        "@crate_index//:num-traits",
        "@crate_index//:serde_bytes",
    ],
)
